*
*         
*
*                     LOC PAPER ANALYSIS
*
*
/*---------------------------------------------------------------

**/

*-------------------------------------------SETUP


*use "C:\Users\xahsce\Desktop\Self-Efficacy Paper\Data\Clean Data\AppendedData.dta", clear
clear all

use "Cleaned_data v2.dta"


****Create some variables
***The simulation variable includes the other treatments, a new variable needs to be created to seperate it from other cross randomisations
gen simulation_v3=simulation
replace simulation_v3=0 if psy_v2==1 & simulation==1
***Do the same for the psy info treatment
gen psy_v3=psy_v2
replace psy_v3=0 if psy_v2==1 & simulation==1

*Create the both treatment
gen psy_sim=0  if psy_v2!=. | simulation!=0
replace psy_sim=1 if psy_v2==1 & simulation==1

*Create a control
gen control=0 if psy_v2==1 | simulation==1
replace control=1 if psy_v2==0




********************************************************************************

*Main Model for simulations and info

********************************************************************************

******Table 1
*---------------------------------------Table 1

*--------------------------------------PREP VARIABLES

*Caste group dummies 
gen general= 0 if Caste_category!=.
replace general=1 if Caste_category==1
gen sc=0 if Caste_category!=.
replace sc=1 if Caste_category==2
gen st=0 if Caste_category!=.
replace st=1 if Caste_category==3
gen obc=0 if Caste_category!=.
replace obc=1 if Caste_category==4
gen sebc=0 if Caste_category!=.
replace sebc=1 if Caste_category==5

*Female dummy 
gen female=0 if HHMem_Gender!=.
replace female=1 if HHMem_Gender==2
*---------------------------------BALANCE TEST

*Outcomes at Baseline
prtest insurance if survey=="Pre-Experiment" & training==1, by(psy_all) 
prtest cropins if survey=="Pre-Experiment" & training==1, by(psy_all) 
ttest fequin if survey=="Baseline" & training==1, by(psy_all)

*Respondent Characteristics 
ttest HHMem_age if survey=="Baseline" & training==1, by(psy_all)
ttest Total_Income if survey=="Baseline" & training==1, by(psy_all)
ttest HHMem_Education if survey=="Baseline" & training==1, by(psy_all)
prtest female if survey=="Baseline" & training==1, by(psy_all)
prtest general if survey=="Baseline" & training==1, by(psy_all)
prtest sc if survey=="Baseline" & training==1, by(psy_all)
prtest st if survey=="Baseline" & training==1, by(psy_all)
prtest obc if survey=="Baseline" & training==1, by(psy_all)
prtest sebc if survey=="Baseline" & training==1, by(psy_all)

*---------------------------------------Table 3

*--------------------------------------PREP VARIABLES


*Create Standardized Agricultural Locus of Control Scale at Baseline
summarize AS_control AS_luck AS_effort if survey=="Pre-Experiment" & training==1, detail

gen s_AS_control_training_B=.
replace s_AS_control_training_B=(AS_control-2.382318)/1.073318 if training==1

gen s_AS_luck_training_B=. 
replace s_AS_luck_training_B=(AS_luck-2.050777)/1.011791 if training==1

gen s_AS_effort_training_B=. 
replace s_AS_effort_training_B=(AS_effort- 2.218041)/1.04112 if training==1

gen AS_index_training_B=(s_AS_control_training_B+s_AS_luck_training_B+s_AS_effort_training_B)/3

sort houseid
by houseid: egen AS_index_training_Base=max(AS_index_training_B)



*Generate Log Income 
gen loginc=log(Total_Income)


*-------------------------------------------Table 3


*Analysis
reg insurance AS_index_training_B ib1.Caste_category ib1.HHMem_Gender HHMem_age HHMem_Education loginc if surveyid==5, cluster(UniqueV_ID)

reg cropins AS_index_training_B ib1.Caste_category ib1.HHMem_Gender HHMem_age HHMem_Education loginc if surveyid==5, cluster(UniqueV_ID)

reg changedvariety AS_index_training_B ib1.Caste_category ib1.HHMem_Gender HHMem_age HHMem_Education loginc if surveyid==5, cluster(UniqueV_ID)

reg fequin AS_index_training_Base ib1.Caste_category ib1.HHMem_Gender HHMem_age HHMem_Education loginc if surveyid==1, cluster(UniqueV_ID)

reg logfequin AS_index_training_Base ib1.Caste_category ib1.HHMem_Gender HHMem_age HHMem_Education loginc if surveyid==1, cluster(UniqueV_ID)


****************************************

*****Table 4

reg AS_index_training psy_v3 simulation_v3 psy_sim if (surveyid==2 | surveyid==3), cluster(Training_SessionID_Revised) robust
est store reg1 

lincom psy_v3 - simulation_v3
lincom psy_v3 - psy_sim
lincom psy_sim - simulation_v3

reg GS_index_training psy_v3 simulation_v3 psy_sim if (surveyid==2 | surveyid==3), cluster(Training_SessionID_Revised) robust
est store reg2 

lincom psy_v3 - simulation_v3
lincom psy_v3 - psy_sim
lincom psy_sim - simulation_v3

reg insurance psy_v3 simulation_v3 psy_sim if (surveyid==2 | surveyid==3), cluster(Training_SessionID_Revised) robust 
est store reg3 

lincom psy_v3 - simulation_v3
lincom psy_v3 - psy_sim
lincom psy_sim - simulation_v3

reg cropins psy_v3 simulation_v3 psy_sim if (surveyid==2 | surveyid==3), cluster(Training_SessionID_Revised) robust 
est store reg4 

lincom psy_v3 - simulation_v3
lincom psy_v3 - psy_sim
lincom psy_sim - simulation_v3

reg fequin psy_v3 simulation_v3 psy_sim if (surveyid==2 | surveyid==3), cluster(Training_SessionID_Revised) robust 
est store reg5 

lincom psy_v3 - simulation_v3
lincom psy_v3 - psy_sim
lincom psy_sim - simulation_v3

reg agrpract psy_v3 simulation_v3 psy_sim if (surveyid==2 | surveyid==3), cluster(Training_SessionID_Revised) robust 
est store reg6 

lincom psy_v3 - simulation_v3
lincom psy_v3 - psy_sim
lincom psy_sim - simulation_v3

reg STRVAdoption psy_v3 simulation_v3 psy_sim if (surveyid==2 | surveyid==3) , cluster(Training_SessionID_Revised) robust 
est store reg7

lincom psy_v3 - simulation_v3
lincom psy_v3 - psy_sim
lincom psy_sim - simulation_v3

reg Asp_RiceYieldLikeToAchieve psy_v3 simulation_v3 psy_sim  if (surveyid==2 | surveyid==3), cluster(Training_SessionID_Revised) robust  
est store reg8

lincom psy_v3 - simulation_v3
lincom psy_v3 - psy_sim
lincom psy_sim - simulation_v3

*Figure 3

coefplot (reg1, mlabels(psy_v3=1 "ALOC" simulation_v3=1 "ALOC" psy_sim=1 "ALOC" ))  ///
(reg2, mlabels(psy_v3=1 "GLOC" simulation_v3=1 "GLOC" psy_sim=1 "GLOC")) ///
(reg3, mlabels(psy_v3=1 "Othr. Insur." simulation_v3=1 "Othr. Insur." psy_sim=1 "Othr. Insur.")) ///
(reg4, mlabels(psy_v3=1 "Crop insurance" simulation_v3=1 "Crop insurance" psy_sim=1 "Crop insurance")) ///
 (reg6, mlabels(psy_v3=1 "Ag. Prcts" simulation_v3=1 "Ag. Prcts" psy_sim=1 "Ag. Prcts" )) ///
(reg7, mlabels(psy_v3=1 "STRVs" simulation_v3=1 "STRVs" psy_sim=1 "STRVs")), bylabel(Panel A) ///
 || (reg5, mlabels(psy_v3=1 "Fertiliser" simulation_v3=1 "Fertiliser" psy_sim=1 "Fertiliser")) ///
 (reg8, mlabels(psy_v3=1 "Aspire Yield" simulation_v3=1 "Aspire Yield" psy_sim=1 "Aspire Yield")),  bylabel(Panel B)  ///
 || , drop(_cons) xline(0) levels(95)  mlabs(vsmall) ///
 ciopts(recast(rcap))  graphregion(fcolor(white)) byopts(xrescale) legend(off)
 
 


****Table 5
 
 
*-------------------------------------CLASSROOM

reg AS_index_classroom psy_v3 simulation_v3 psy_sim if classroom==1 & (surveyid==2 | surveyid==3), cluster(Training_SessionID_Revised) robust
lincom psy_v3 - simulation_v3
lincom psy_v3 - psy_sim
lincom psy_sim - simulation_v3

reg GS_index_classroom psy_v3 simulation_v3 psy_sim if classroom==1 & (surveyid==2 | surveyid==3), cluster(Training_SessionID_Revised) robust
lincom psy_v3 - simulation_v3
lincom psy_v3 - psy_sim
lincom psy_sim - simulation_v3

reg insurance psy_v3 simulation_v3 psy_sim if classroom==1 & (surveyid==2 | surveyid==3), cluster(Training_SessionID_Revised) robust 
lincom psy_v3 - simulation_v3
lincom psy_v3 - psy_sim
lincom psy_sim - simulation_v3

reg cropins psy_v3 simulation_v3 psy_sim if classroom==1 & (surveyid==2 | surveyid==3), cluster(Training_SessionID_Revised) robust 
lincom psy_v3 - simulation_v3
lincom psy_v3 - psy_sim
lincom psy_sim - simulation_v3

reg fequin psy_v3 simulation_v3 psy_sim if classroom==1 & (surveyid==2 | surveyid==3), cluster(Training_SessionID_Revised) robust 
lincom psy_v3 - simulation_v3
lincom psy_v3 - psy_sim
lincom psy_sim - simulation_v3

reg agrpract psy_v3 simulation_v3 psy_sim if classroom==1 & (surveyid==2 | surveyid==3), cluster(Training_SessionID_Revised) robust 
lincom psy_v3 - simulation_v3
lincom psy_v3 - psy_sim
lincom psy_sim - simulation_v3

reg STRVAdoption psy_v3 simulation_v3 psy_sim if classroom==1 & (surveyid==2 | surveyid==3), cluster(Training_SessionID_Revised) robust 
lincom psy_v3 - simulation_v3
lincom psy_v3 - psy_sim
lincom psy_sim - simulation_v3

reg Asp_RiceYieldLikeToAchieve psy_v3 simulation_v3 psy_sim if classroom==1 & (surveyid==2 | surveyid==3), cluster(Training_SessionID_Revised) robust  
lincom psy_v3 - simulation_v3
lincom psy_v3 - psy_sim
lincom psy_sim - simulation_v3


*-----------------------------------VIDEO

reg AS_index_video psy_v3 simulation_v3 psy_sim if video==1 & (surveyid==2 | surveyid==3), cluster(Training_SessionID_Revised) robust
lincom psy_v3 - simulation_v3
lincom psy_v3 - psy_sim
lincom psy_sim - simulation_v3

reg GS_index_video psy_v3 simulation_v3 psy_sim if video==1 & (surveyid==2 | surveyid==3), cluster(Training_SessionID_Revised) robust
lincom psy_v3 - simulation_v3
lincom psy_v3 - psy_sim
lincom psy_sim - simulation_v3

reg insurance psy_v3 simulation_v3 psy_sim if video==1 & (surveyid==2 | surveyid==3), cluster(Training_SessionID_Revised) robust 
lincom psy_v3 - simulation_v3
lincom psy_v3 - psy_sim
lincom psy_sim - simulation_v3

reg cropins psy_v3 simulation_v3 psy_sim if video==1 & (surveyid==2 | surveyid==3), cluster(Training_SessionID_Revised) robust 
lincom psy_v3 - simulation_v3
lincom psy_v3 - psy_sim
lincom psy_sim - simulation_v3

reg fequin psy_v3 simulation_v3 psy_sim if video==1 & (surveyid==2 | surveyid==3), cluster(Training_SessionID_Revised) robust 
lincom psy_v3 - simulation_v3
lincom psy_v3 - psy_sim
lincom psy_sim - simulation_v3

reg agrpract psy_v3 simulation_v3 psy_sim if video==1 & (surveyid==2 | surveyid==3), cluster(Training_SessionID_Revised) robust 
lincom psy_v3 - simulation_v3
lincom psy_v3 - psy_sim
lincom psy_sim - simulation_v3

reg STRVAdoption psy_v3 simulation_v3 psy_sim if video==1 & (surveyid==2 | surveyid==3), cluster(Training_SessionID_Revised) robust 
lincom psy_v3 - simulation_v3
lincom psy_v3 - psy_sim
lincom psy_sim - simulation_v3

reg Asp_RiceYieldLikeToAchieve psy_v3 simulation_v3 psy_sim if video==1 & (surveyid==2 | surveyid==3), cluster(Training_SessionID_Revised) robust  
lincom psy_v3 - simulation_v3
lincom psy_v3 - psy_sim
lincom psy_sim - simulation_v3


******************************************************************************
****Table 6
**Covid analysis
****************************************************************************
gen covid=0 if surveyid==2
replace covid=1 if surveyid==3

gen psy_v2_cv=psy_v3*covid
gen simulation_cv=simulation_v3*covid
gen psy_sim_cv=psy_sim*covid

*Estimates
reg AS_index_training psy_v3 simulation_v3 psy_sim covid psy_v2_cv simulation_cv psy_sim_cv if (surveyid==2 | surveyid==3), cluster(Training_SessionID_Revised) robust

reg GS_index_training psy_v3 simulation_v3 psy_sim covid psy_v2_cv simulation_cv psy_sim_cv if (surveyid==2 | surveyid==3), cluster(Training_SessionID_Revised) robust

reg insurance psy_v3 simulation_v3 psy_sim covid psy_v2_cv simulation_cv psy_sim_cv if (surveyid==2 | surveyid==3), cluster(Training_SessionID_Revised) robust 

reg cropins psy_v3 simulation_v3 psy_sim covid psy_v2_cv simulation_cv psy_sim_cv if (surveyid==2 | surveyid==3), cluster(Training_SessionID_Revised) robust 

reg fequin psy_v3 simulation_v3 psy_sim covid psy_v2_cv simulation_cv psy_sim_cv if (surveyid==2 | surveyid==3), cluster(Training_SessionID_Revised) robust 

reg agrpract psy_v3 simulation_v3 psy_sim covid psy_v2_cv simulation_cv psy_sim_cv if (surveyid==2 | surveyid==3), cluster(Training_SessionID_Revised) robust 

reg STRVAdoption psy_v3 simulation_v3 psy_sim covid psy_v2_cv simulation_cv psy_sim_cv if (surveyid==2 | surveyid==3) , cluster(Training_SessionID_Revised) robust 

reg Asp_RiceYieldLikeToAchieve psy_v3 simulation_v3 psy_sim covid psy_v2_cv simulation_cv psy_sim_cv if (surveyid==2 | surveyid==3), cluster(Training_SessionID_Revised) robust  


********************************************************************
***Table 7
*Double Lasso
*********************************************************************



**Drop Telephone surveyid
drop if surveyid==4

*Clean controls
sort houseid
***Fix up the main outcomes so they can be used with baseline data
by houseid: egen ALOCmerge=max(AS_index_training)
by houseid: egen ALOCmerge_class=max(AS_index_classroom)
by houseid: egen ALOCmerge_video=max(AS_index_video)

by houseid: egen GS_index_training_x=max(GS_index_training)
by houseid: egen GS_index_class_x=max(GS_index_classroom)
by houseid: egen GS_index_video_x=max(GS_index_video)


by houseid: egen insurance_x=max(insurance)
by houseid: egen cropins_x=max(cropins)
by houseid: egen fequin_x=max(fequin)
by houseid: egen agrpract_x=max(agrpract)
by houseid: egen STRVAdoption_x=max(STRVAdoption)
by houseid: egen Asp_RiceYieldLikeToAchieve_x=max(Asp_RiceYieldLikeToAchieve)


***Keep the baseline
keep if (surveyid==1 & psy_all!=.)


gen ravensQ1=0 if Ravens_Matrices_1!=.
replace ravensQ1=1 if Ravens_Matrices_1==8

gen ravensQ2=0 if Ravens_Matrices_2!=.
replace ravensQ2=1 if Ravens_Matrices_2==4

gen ravensQ3=0 if Ravens_Matrices_3!=.
replace ravensQ3=1 if Ravens_Matrices_3==5

gen ravensQ4=0 if Ravens_Matrices_4!=.
replace ravensQ4=1 if Ravens_Matrices_4==1

gen ravensQ5=0 if Ravens_Matrices_5!=.
replace ravensQ5=1 if Ravens_Matrices_5==2

gen ravensQ6=0 if Ravens_Matrices_6!=.
replace ravensQ6=1 if Ravens_Matrices_6==5

gen ravensQ7=0 if Ravens_Matrices_7!=.
replace ravensQ7=1 if Ravens_Matrices_7==6

gen ravensQ8=0 if Ravens_Matrices_8!=.
replace ravensQ8=1 if Ravens_Matrices_8==3
egen no_correct_ravens=rowtotal(ravensQ1 ravensQ2 ravensQ3 ravensQ4 ravensQ5 ravensQ6 ravensQ7 ravensQ8)

***Number if people who you know who have registered for crop insurance
replace Number_PeopleInsd=. if Number_PeopleInsd==9999

**Financial Literacy
gen finlit_Q1=1 if FinLiteracy_1==3
gen finlit_Q2=1 if FinLiteracy_2==2
gen finlit_Q3=1 if FinLiteracy_3==3
gen finlit_Q4=1 if FinLiteracy_4==2
egen fitlit_nocorrect=rowtotal(finlit_Q1 finlit_Q2 finlit_Q3 finlit_Q4)

***Depression scale
egen depression_scale=rowtotal(Feeling_Tired Appetite Sleep_Status Speaking_Status Concentration_Question Interestingness_Status Feeling_Down FeelingBad_Yourself Hurting_Yourself)

***Stress
*reorder some variables
recode Stress_Scale_Q2 (1=5) (2=4) (3=3) (4=2) (5=1)
 recode Stress_Scale_Q3 (1=5) (2=4) (3=3) (4=2) (5=1)
egen stress_scale=rowtotal(Stress_Scale_Q1 Stress_Scale_Q2 Stress_Scale_Q3 Stress_Scale_Q4)
 
**Girsl below 5
replace GIRLS_BELOW_5=5 if GIRLS_BELOW_5==50

*Stock Preseason
replace Stock_PreSeason=. if Stock_PreSeason==9999
*Store self consumption
replace Store_SelfConsumption=. if Store_SelfConsumption==9999

*Distance to the nearest market
replace Distance_NMarket=. if Distance_NMarket==9999

*Premium Awareness
replace Premium_Awareness=3 if Premium_Awareness==9999

*Currently availing the scheme
gen has_crop_insurance=0
replace has_crop_insurance=1 if Status_InsAvailing==2

*Distance to insurance faciltation centers
replace Distance_FinInstitution=. if Distance_FinInstitution==9999

***
replace Kharif_NYield=. if Kharif_NYield==9999
replace Lowest_Yield=. if Lowest_Yield==9999

 
global controlslasso i.Caste_category i.Religion c.HH_SIZE  c.TotalCultivated_Area c.Total_Production c.no_correct_ravens  ///
i.Electricity_Access c.Kharif_NYield i.Credit_Necessity i.Credit_Frequency c.prodquin c.Total_Income i.HHMem_Gender ///
 c.HHMem_age c.HHMem_Education c.PRisk_Frequency i.GIRLS_BELOW_5 i.BOYS_BELOW_5 c.TotalCultivated_Plots ///
 c.TotalCultivated_IrrigableK c.Stock_PreSeason c.Quantity_Sold i.Premium_Awareness i.Insquiz_Purpose ///
 i.InsQuiz_Premuim i.Awareness_PMFBY c.Lowest_Yield i.First_ThreatRice i.Second_ThreatRice i.First_RStrategy ///
 i.Time_FL i.Risk_FL i.GreenRed_Q1 i.GreenRed_Q2 i.YellowGreen_Q1 i.YellowGreen_Q2 i.YellowGreen_Q3 ///
 i.YellowGreen_Q4 i.Perception_CConstrain c.Number_PeopleInsd c.fitlit_nocorrect c.depression_scale ///
 c.stress_scale c.Store_SelfConsumption c.Distance_NMarket i.has_crop_insurance c.Distance_FinInstitution


global controlsdum i.Caste_category i.Religion i.Credit_Necessity i.Credit_Frequency ///
i.InsQuiz_Premuim i.Awareness_PMFBY c.Lowest_Yield i.First_ThreatRice i.Second_ThreatRice i.First_RStrategy 
sum $controlslasso



***Estimates
pdslasso ALOCmerge psy_v3 simulation_v3 psy_sim ($controlslasso) , noi cluster(Training_SessionID_Revised)  lopt(prestd)	

pdslasso GS_index_training_x psy_v3 simulation_v3 psy_sim ($controlslasso) , noi cluster(Training_SessionID_Revised)  lopt(prestd)	

pdslasso insurance_x psy_v3 simulation_v3 psy_sim ($controlslasso) , noi cluster(Training_SessionID_Revised)  lopt(prestd)

pdslasso cropins_x psy_v3 simulation_v3 psy_sim ($controlslasso) , noi cluster(Training_SessionID_Revised)  lopt(prestd)

pdslasso fequin_x psy_v3 simulation_v3 psy_sim ($controlslasso) , noi cluster(Training_SessionID_Revised)  lopt(prestd)

pdslasso agrpract_x psy_v3 simulation_v3 psy_sim ($controlslasso) , noi cluster(Training_SessionID_Revised)  lopt(prestd)

pdslasso STRVAdoption_x psy_v3 simulation_v3 psy_sim ($controlslasso) , noi cluster(Training_SessionID_Revised)  lopt(prestd)

pdslasso Asp_RiceYieldLikeToAchieve_x psy_v3 simulation_v3 psy_sim ($controlslasso) , noi cluster(Training_SessionID_Revised)  lopt(prestd)





